unit Con_CondFaturamento;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids,
  Db, Dbtables, TFlatButtonUnit;

type
  TFrmCon_CondFaturamento = class(TFrmConsulta)
    Label1: TLabel;
    EdtDescricao: TEdit;
    DbgCondFaturamento: TDBGrid;
    btnGravar: TFlatButton;
    procedure BtnFecharClick(Sender: TObject);
    procedure EdtDescricaoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnGravarClick(Sender: TObject);
    procedure DbgCondFaturamentoDblClick(Sender: TObject);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    Conf_codigo: string;
  end;

var
  FrmCon_CondFaturamento: TFrmCon_CondFaturamento;

implementation

uses Dm, Biblio, clsCondFaturamento, Cad_CondFaturamento, menu;

{$R *.DFM}

var
  CondFaturamento: TCondFaturamento;
  tds: Tdatasource;
  tq: Tquery;

procedure TFrmCon_CondFaturamento.BtnFecharClick(Sender: TObject);
begin
  inherited;
  Conf_codigo := tq.fieldbyname('Conf_codigo').asstring;
  tds.free;
  tq.free;
end;

procedure TFrmCon_CondFaturamento.EdtDescricaoKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key = 12 then begin
    FazConsulta;
    EdtDescricao.setfocus;
  end;
end;

procedure TFrmCon_CondFaturamento.FormActivate(Sender: TObject);
begin
  inherited;
  if FileExists(caminho_personal + 'belquimica') then begin
    btnGravar.Visible := False;
  end;
  tds := TDataSource.create(FrmCon_CondFaturamento);
  tq := Tquery.create(FrmCon_CondFaturamento);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  tds.DataSet := tq;
  fazconsulta;
  EdtDescricao.setfocus;
end;

procedure TFrmCon_CondFaturamento.FazConsulta;
begin
  if EdtDescricao.text = '' then
    EdtDescricao.text := ' ';
  CondFaturamento.Consultar(tq, EdtDescricao.text);
  tq.open;
  dbgCondFaturamento.DataSource := tds;
  dbgCondFaturamento.Refresh;
end;

procedure TFrmCon_CondFaturamento.FormCreate(Sender: TObject);
begin
  inherited;
  CondFaturamento := TCondFaturamento.Create;
end;

procedure TFrmCon_CondFaturamento.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  CondFaturamento.free;
end;

procedure TFrmCon_CondFaturamento.btnGravarClick(Sender: TObject);
var
  f1: TFrmCad_CondFaturamento;
begin
  inherited;
  f1 := TFrmCad_CondFaturamento.Create(self);
  f1.btnC_CondFaturamento.visible := False;
  f1.ShowModal;
  f1.Free;
  FazConsulta;
end;

procedure TFrmCon_CondFaturamento.DbgCondFaturamentoDblClick(
  Sender: TObject);
begin
  inherited;
  BtnFecharClick(Sender);
end;

end.
